package cn.dnui_cr503.dnuifood_16110100503.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.dnui_cr503.dnuifood_16110100503.R;
import cn.dnui_cr503.dnuifood_16110100503.bean.CommentsBean;

/**
 * Created by chengrui on 2018/11/23.
 */

public class CommentsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List<CommentsBean> mDataList;
    private LayoutInflater mLayoutInflater;

    public CommentsAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.comments_item,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final CommentsBean entity = (CommentsBean) mDataList.get(position);
        if (null == entity)
            return;
        CommentsAdapter.ViewHolder viewHolder = (CommentsAdapter.ViewHolder) holder;
        viewHolder.comments_text.setText(entity.getContent());
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView comments_text;
        public ViewHolder(View view) {
            super(view);
            comments_text=(TextView)view.findViewById(R.id.comments_text);
        }
    }
}
